<?php
class DB{
    private $dbhost;//数据库地址
    private $dbuser;//数据库用户名
    private $dbpass;//数据库密码
    private $dbname;//数据库名
    private $dbset;//字符集

    function  __construct($dbhost,$dbuser,$dbpass,$dbname,$dbset) {
        $this->dbhost=$dbhost;
        $this->dbuser=$dbuser;
        $this->dbpass=$dbpass;
        $this->dbname=$dbname;
        $this->dbset=$dbset;
        $this->connect();
    }

    function connect(){
        $conn=mysql_connect($this->dbhost, $this->dbuser, $this->dbpass) or die($this->error());//连接数据库
        mysql_select_db($this->dbname,$conn)or die($this->error());//选择数据库
        mysql_query("SET NAMES $this->dbset");//设置字符集
    }

    function query($query) {
        return mysql_query($query);
    }

    function num($result) {
        return mysql_num_rows($result);
    }
    function row($result) {
        return mysql_fetch_assoc($result);
    }
    function error() {
        return mysql_error();
    }
}
?>